package sg.edu.nus.iss.vmcs.customer;

/*
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * This control object implements the coin denomination selection (button
 * presses by the customer) on the Customer Panel when coins are entered for a
 * product to be dispensed. Action will be performed in correspondence to the
 * button pressed. 
 * This object is act as the adapter between CoinReciver and CoinInputBox
 * 
 * @author Justin
 * 		- Implementation of adapter pattern in 'Enter Coin' use case
 * 		- renamed from CoinInputListner to CoinInputBoxAdapter.
 * 
 */
public class CoinInputBoxHWAdapter implements ActionListener, CoinInputBoxTarget {
	
	private CoinReceiver coinReceiver;
	private CoinInputBox coinInputBox;
	
	public CoinInputBoxHWAdapter(CoinReceiver coinReceiver) {
		this.coinReceiver = coinReceiver;		
	}
	
	public void actionPerformed(ActionEvent e) {
		Button source = (Button) e.getSource();
		String actionCommand = source.getActionCommand();
		double weight = Double.parseDouble(actionCommand);
		System.out.println("CoinInputBoxHWAdapter::Actionperformed()");
		coinReceiver.receiveCoin(weight);		
	}
	
	public void updateStatus(boolean active){
		System.out.println("CoinInputBoxHWAdapter::updateStatus()");
		coinInputBox.setActive(active);
	}

	public void setCoinInputBox(CoinInputBox coinInputBox) {
		this.coinInputBox = coinInputBox;
	}
	
	public TransactionController getTransactionController() {
		return coinReceiver.getTransactionController();
	}
	
}
